package acronym

import (
	"strings"
	"unicode"
)

const testVersion = 2

func f(c rune) bool {
	return !unicode.IsLetter(c) // && !unicode.IsNumber(c)
}

func Abbreviate(in string) string {
	var phraseSplit = strings.FieldsFunc(in, f)
	var acronymArray = make([]string, len(phraseSplit))
	for i := 0; i < len(phraseSplit); i++ {
		if strings.ToUpper(phraseSplit[i]) == phraseSplit[i] {
			title := strings.Title(strings.ToLower(phraseSplit[i]))
			acronymArray = append(acronymArray, title[0:1])
		} else {
			title := strings.Title(phraseSplit[i])
			for j := 0; j < len(title)-1; j++ {
				idx := title[j : j+1]
				if idx <= "Z" && idx >= "A" {
					acronymArray = append(acronymArray, idx)
				}
			}
		}
	}
	return strings.Join(acronymArray, "")
}
